Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/app/cout/assemblage/[code]/page.tsx9 * Module : app10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-09-0812 * Last Modified : 2026-09-0813 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Vrai-Prix — méthode du coût : fiche d'un assemblage.43import type { Metadata } from "next";44import { notFound } from "next/navigation";45import AssemblyDetail, { type AssemblyDetailData } from "@/components/cout/AssemblyDetail";46import { buildContext, loadLocations } from "@/lib/cost/catalog";47import { assemblyUnitCost } from "@/lib/cost/engine";48import { cached } from "@/lib/cost/cache";4950export const dynamic = "force-dynamic";5152function load(code: string): AssemblyDetailData | null {53 return cached(`assembly-page:${code}`, 10 * 60_000, () => {54 const ctx = buildContext({ locationCode: "QC-MTL" });55 const a = ctx.assemblies.get(code);56 if (!a) return null;57 const unit = assemblyUnitCost(a, ctx);58 const regional = loadLocations().map((l) => ({ code: l.code, nameFr: l.nameFr, nameEn: l.nameEn, direct: Math.round(100 * (unit.material * l.materialFactor + unit.labour * l.labourFactor + unit.equipment * l.equipmentFactor)) / 100, materialFactor: l.materialFactor, labourFactor: l.labourFactor, equipmentFactor: l.equipmentFactor }));59 const history: AssemblyDetailData["history"] = [];60 const now = new Date(ctx.asOf);61 for (let k = 7; k >= 0; k--) {62 const d = new Date(now); d.setMonth(d.getMonth() - 3 * k);63 const asOf = d.toISOString().slice(0, 10);64 const c2 = k === 0 ? ctx : buildContext({ asOf, locationCode: "QC-MTL" });65 const u2 = assemblyUnitCost(a, c2);66 const kinds = new Set(u2.components.filter((c) => c.itemCode).map((c) => c.provenance.kind));67 history.push({ date: asOf, direct: u2.direct, material: u2.material, labour: u2.labour, equipment: u2.equipment, kind: kinds.has("observed") || kinds.has("official") ? "observed" : kinds.has("indexed") ? "indexed" : "reference" });68 }69 const neighbours = [...ctx.assemblies.values()].filter((x) => x.category === a.category && x.code !== a.code).slice(0, 8).map((x) => { const u = assemblyUnitCost(x, ctx); return { code: x.code, nameFr: x.nameFr, nameEn: x.nameEn, unit: x.unit, direct: u.direct }; });70 return { asOf: ctx.asOf, location: ctx.location, assembly: a, unit, regional, history, neighbours };71 });72}7374export async function generateMetadata({ params }: { params: Promise<{ code: string }> }): Promise<Metadata> {75 const { code } = await params;76 const d = load(decodeURIComponent(code));77 if (!d) return { title: "Assemblage introuvable" };78 return { title: `${d.assembly.nameFr} — ${d.unit.direct.toLocaleString("fr-CA", { maximumFractionDigits: 2 })} $ / ${d.assembly.unit} · assemblage`, description: d.assembly.descriptionFr, alternates: { canonical: `/cout/assemblage/${encodeURIComponent(d.assembly.code)}` } };79}8081export default async function AssemblyPage({ params }: { params: Promise<{ code: string }> }) {82 const { code } = await params;83 const d = load(decodeURIComponent(code));84 if (!d) notFound();85 return <AssemblyDetail data={d} />;86}87